-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ECS] Modify ELB listener rules other than defaults without adding config #4733
Conversation
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
d79472e
to
8f2ba1e
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #4733 +/- ##
==========================================
- Coverage 30.84% 30.84% -0.01%
==========================================
Files 221 222 +1
Lines 25993 26037 +44
==========================================
+ Hits 8018 8030 +12
- Misses 17325 17357 +32
Partials 650 650 ☔ View full report in Codecov by Sentry. |
/review |
PR AnalysisMain theme
PR summary
Type of PR
PR Feedback:General suggestions
Code feedback
Security concerns:
The PR does not introduce changes that are directly related to common security issues. It primarily deals with load balancer rule modifications and does not involve user input handling, database operations, or other areas typically associated with security vulnerabilities like SQL injection, XSS, or CSRF. |
// Sort so that the both slices have the same target groups. | ||
sort.Slice(c, func(i, j int) bool { | ||
return c[i].TargetGroupArn < c[j].TargetGroupArn | ||
}) | ||
sort.Slice(forwardActionTargets, func(i, j int) bool { | ||
return *forwardActionTargets[i].TargetGroupArn < *forwardActionTargets[j].TargetGroupArn | ||
}) | ||
|
||
for i := range c { | ||
if c[i].TargetGroupArn != *forwardActionTargets[i].TargetGroupArn { | ||
return false | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of sorting both, then iterating through, using an extra map with TargetGroupArn as key could provide a better performance. It's a more straightforward approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@khanhtc1202 Thanks! I'll try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@khanhtc1202
I fixed on 727e13c
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
}) | ||
if err != nil { | ||
return fmt.Errorf("error describing listener %s: %w", listenerArn, err) | ||
return fmt.Errorf("failed to describe rules %s: %w", listenerArn, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("failed to describe rules %s: %w", listenerArn, err) | |
return fmt.Errorf("failed to describe rules of listener %s: %w", listenerArn, err) |
TargetGroupArn: aws.String(routingTrafficCfg[1].TargetGroupArn), | ||
Weight: aws.Int32(int32(routingTrafficCfg[1].Weight)), | ||
for _, rule := range describeRulesOutput.Rules { | ||
var modifiedActions []elbtypes.Action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var modifiedActions []elbtypes.Action | |
modifiedActions := make([]elbtypes.Action, 0, len(rule.Actions)) |
LGTM with some nits 👍 |
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
@khanhtc1202 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great improvement 👍
@ffjlabo plz check 👀👀 |
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tc := tc
is needed 👀
ref: https://www.tddfellow.com/blog/2016/01/08/why-do-you-need-to-be-careful-with-loop-variable-in-go/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ffjlabo Thank you so much! I fixed
cMap := make(map[string]bool) | ||
for _, item := range c { | ||
cMap[item.TargetGroupArn] = true | ||
} | ||
|
||
for _, target := range forwardActionTargets { | ||
if !cMap[*target.TargetGroupArn] { | ||
return false | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] It would be nice to use struct{}
empty struct :)
This is more efficient because it does not allocate memory.
cMap := make(map[string]bool) | |
for _, item := range c { | |
cMap[item.TargetGroupArn] = true | |
} | |
for _, target := range forwardActionTargets { | |
if !cMap[*target.TargetGroupArn] { | |
return false | |
} | |
} | |
cMap := make(map[string]struct{}) | |
for _, item := range c { | |
cMap[item.TargetGroupArn] = struct{}{} | |
} | |
for _, target := range forwardActionTargets { | |
if _, ok := cMap[*target.TargetGroupArn]; !ok { | |
return false | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ffjlabo Thank you so much! I fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ffjlabo
I fixed again to use tc:=tc
as you suggested instead of tc:=testcase
because I found an article that recommends to use the same name.
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
…nfig (pipe-cd#4733) * Add a func of comparing target groups Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * Modify ModifyListeners to edit rules other than default Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * Modify comments Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * Use ModifyLister to modify the default rules Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * Use map to compare target groups Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * Fix log and use make() Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * Refactored to memory efficient Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * Fix reference of loop var of testcases Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * Modify loop variable name in test Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> --------- Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
What this PR does / why we need it:
Modifying listener rules which is not the default rule without specifying in app.pipecd.config, unlike #4726.
Which issue(s) this PR fixes:
Fixes #4725
Does this PR introduce a user-facing change?: no
** A short explanation **
If the ELB and app.pipecd.yaml are as below, the rules that will be modified are
rule-A1
,rule-B1
andrule-B2
since they have the same target groups as app.pipecd.yaml.
app.pipecd.yaml: